n = int(input())
lst = list()
for i in range(n):
    lst.append(list(map(int, input().split())))

s = 0
for i in range(n):
    for j in range(n):
        print('%3d' % lst[i][j], end='\n' if j == n - 1 else '')
        if i == j or i + j == n - 1:
            s = s + lst[i][j]
print('sum = %d' % s)